library(REmap)

bju <- get_geo_position("北京大学")

ustc <- get_geo_position("中国科学技术大学")

set.seed(125)
origin = rep("北京",10)
destination = c('上海','广州','大连','南宁','南昌',
                '拉萨','长春','包头','重庆','常州')
dat = data.frame(origin,destination)
out = remap(dat,title = "REmap实例数据",subtitle = "theme:Dark")
plot(out)

# Hot map ----
cities <- mapNames("guangdong")
cities

city_geo <- get_geo_position(cities)
percent <- runif(21, min = 0.25, max = 0.9)
head(percent)

data_all <- data.frame(city_geo[, 1:2], percent)
head(data_all)

result <- remapH(data_all,
                  maptype = "guangdong",
                  theme = get_theme("Bright"),
                  blurSize = 35,
                  color = "red",
                  minAlpha = 10,
                  opacity = 1)
plot(result)


# Position map ----

#北京大学名单
University <- c(
  "北京大学",
  "清华大学",
  "中国人民大学",
  "北京外国语大学",
  "北京理工大学",
  "北京邮电大学",
  "中央音乐学院",
  "中央民族大学",
  "北京体育大学",
  "中国政法大学"
)

#获取经纬度
Uni_Geo <- get_geo_position(University)

#绘制方位图
Uni_resutl <- remapB(
  markPointData = data.frame(Uni_Geo$city),
  markPointTheme = markPointControl(
    symbol = "circle",
    effect = TRUE,
    #动态效果
    symbolSize = 8,
    color = "red"
  ),
  geoData = Uni_Geo
  
)
plot(Uni_resutl)


# Line map ----
location <- c("北京市", "广州市", "深圳市", "上海市", "昆明市")
loc_Geo <- get_geo_position(location)

#拆分起始站点
startPoint <- location[1:4]
terminalPoint <- location[2:5]

#组合成数据框，用于连线
data_DF <- data.frame(startPoint, terminalPoint)

#绘制连线图
loc_result <- remapB(
  center = get_city_coord("北京市"),
  color = "Blue",
  markLineData = data_DF,
  markLineTheme = markLineControl(
    effect = TRUE,
    smoothness = 0,
    symbolSize = c(0, 1)
  ),
  geoData = loc_Geo
)

plot(loc_result)


# Moving map ----
#虚构一份数据
startPoint <- rep("武汉市", 8)
destination <- c("北京市", "广州市", "深圳市", "上海市", "昆明市", "长春市", "西宁", "南宁市")

#构建数据框
data_DF <- data.frame(startPoint, destination)

#绘制迁移图
result <- remap(data_DF, theme = get_theme("Dark"))
plot(result)

# Fill map ----
#虚构一份数据:城市名单及对应值
city <- mapNames("guangdong")
value <- runif(21, min = 1, max = 100)

#构建数据框
data_DF <- data.frame(city, value)


#绘制填充地图
result <- remapC(
  data_DF,
  title = "广东省热力图",
  maptype = "guangdong",
  color = "green",
  theme = get_theme("Dark"),
  maxdata = 100,
  mindata = 1
)
plot(result)



